-
-
Notifications
You must be signed in to change notification settings - Fork 741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor parameterCount to optimize performance #591
Refactor parameterCount to optimize performance #591
Conversation
Now that body-parser targets Node.js 18, we can finally use String.split to count all the '&'s in parameterCount body. This makes the function roughly 2x faster, according to this jsperf: https://jsperf.app/niqepi/2 Fun fact: if you run this jsperf in Firefox, the old implementation will get record-breaking speeds, while the _new_ one will be roughly 7x slower. Thankfully, both Chrome/Node and Bun/Safari engines show the opposite results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't quite see the same results in the micro-benchmark, but it was still an improvement. Additionally it is a nice legibility improvement to simplify this method so even if it was relatively equivalent perf I would not mind merging it. Just going to let it sit to see if anyone else had input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make the linter happy again :)
Now that body-parser targets Node.js 18, we can finally use String.split to count all the
&
s inparameterCount
body. This makes the function roughly 2x faster in Chrome/Node.js engine (and about 2.5x faster in Safari/Bun engine), according to this jsperf: https://jsperf.app/niqepi/2Fun fact: if you run this jsperf in Firefox, the old implementation will get speeds unmatched by any other engine, while the new one will be roughly 7x slower. Thankfully, that's only the case in Firefox.
a